/*
 * AbstractXMLResource.h
 *
 *  Created on: 16 févr. 2011
 *      Author: seeme
 *      Plus utilisée pour le moment (remplacée par boost::serialization)
 *      permet de lire puis de parser un fichier xml
 */

#ifndef ABSTRACTXMLRESOURCE_H_
#define ABSTRACTXMLRESOURCE_H_

#include "../../../Dependency/xml/tinyxml.h"
#include "../Resource.h"
#include <sstream>
#include <fstream>

class AbstractXMLResource: public Resource {
public:
	AbstractXMLResource(std::string filename, std::string filepath): Resource(filename, filepath){}

	AbstractXMLResource(){};


	virtual ~AbstractXMLResource(){};

protected:
	TiXmlDocument m_data;
	void openFile(){
		//Log::d("AbstractXMLResource") << "Loading file";
		//Use old C-style is bad...
		FILE* f = fopen(m_filePath.c_str(), "r");

		if(!m_data.LoadFile(f)){
			Log::e("AbstractXMLResource") << "Error loading file: " << m_name.c_str() << "at "
					<<m_filePath.c_str() << ":" << m_data.ErrorId() << ", " << m_data.ErrorDesc();
		}

		unsigned int length = 0;
		fseek(f, 0, SEEK_END );
		length = ftell(f);
		fseek(f, 0, SEEK_SET );

		m_size = length;
	}
};

#endif /* ABSTRACTXMLRESOURCE_H_ */
